package org.git.movie.videojiexi.service.impl;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestA {
    private static Logger log = LoggerFactory.getLogger(TestA.class);
    public static void main(String[] args) {
        List<Integer> a1 = new ArrayList<>();
        List<Integer> a2  = new ArrayList<>();

        List<Integer> repList  = new ArrayList<>();

        int index= 0;
        int jinwei = 0;

        int max   = Math.max(a1.size(),a2.size() );

        Map<String,Integer> temMap = null;
        TestA testA = new TestA();
        for(index = 0;index < max; index++){
            temMap = testA.subMethod(  a1 ,   a2,   index,   jinwei );

            jinwei = temMap.get("jinweiReturn");
            repList.add(temMap.get("result"));
        }

        log.info("返回结果为："+ JSON.toJSONString(repList));

    }

    /**
     *  map里记录进位值和新数组对应位置的值
     * @param a1
     * @param a2
     * @param index
     * @param jinwei
     * @return
     */
    public Map<String,Integer> subMethod(List<Integer> a1 , List<Integer> a2, int index, int jinwei ){
        int a1Size = a1.size();
        int a2Size = a2.size();
        int newA1Value = 0;
        int newA2Value = 0;
        int sumValue = 0;
        if(a1Size > index ){
            newA1Value = a1.get(index);
        }
        if(a2Size > index ){
            newA2Value = a2.get(index);
        }
        sumValue = newA1Value+newA2Value+jinwei;

        int result = sumValue % 10;
        int jinweiReturn =  sumValue / 10;

        Map<String,Integer>  rep = new HashMap<>();
        rep.put("result",result);
        rep.put("jinweiReturn",jinweiReturn);

        return rep;

    }
}
